package com.sunny.crawler.pipeline;

import com.sunny.entity.ApiMetaNameEntity;
import com.sunny.entity.ApiMetaParamEntity;
import com.sunny.entity.ApiMetaResultEntity;
import com.sunny.service.FinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.List;

@Component
public class FinancePipeline implements Pipeline {

    @Autowired
    private FinanceService financeService;

    @Override
    @Transactional
    public void process(ResultItems resultItems, Task task) {

        ApiMetaNameEntity nameEntity = resultItems.get("name");
        List<ApiMetaParamEntity> paramList = resultItems.get("param");
        List<ApiMetaResultEntity> resultEntityList = resultItems.get("result");
        financeService.addMetaName(nameEntity);
        financeService.addMetaParam(paramList);
        financeService.addMetaResult(resultEntityList);

    }
}